package chpt11;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EmailSpider {
    public static void main(String[] args) throws IOException {
    	URL url =new URL("http://www.example.com");
    	BufferedReader buf=new BufferedReader(new InputStreamReader(url.openStream()));
    	String regex = "[\\w-]+@[\\w-]+(\\.[\\w-]+)+";
    	Pattern p= Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
    	String line=null;
    	while((line=buf.readLine())!=null){
    		Matcher m=p.matcher(line);
    		while(m.find()){
    			System.out.println(m.group());
    		}
    	}
    }
}